package com.zkflzl.store.controller;

import com.zkflzl.store.annotation.AuthCheck;
import com.zkflzl.store.common.BaseResponse;
import com.zkflzl.store.constant.UserConstant;
import com.zkflzl.store.model.dto.msg.MsgAddRequest;
import com.zkflzl.store.model.dto.msg.MsgListRequest;
import com.zkflzl.store.service.MsgService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
@RequestMapping("/msg")
@Api(tags = "消息模块")
public class MsgController {
    @Resource
    private MsgService msgService;


    /**
     * 新增消息
     */
    public void addMsg(@RequestBody MsgAddRequest msgAddRequest, HttpServletRequest request) {
        msgService.addMsg(msgAddRequest, request);
    }

    /**
     * 更新消息
     */
    @PostMapping("/update")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    public void updateMsg(@RequestParam Long id, HttpServletRequest request) {
        msgService.updateShop(id, request);
    }

    /**
     * 分页获取消息
     */
    @PostMapping("/sel")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    public BaseResponse selMsg(@RequestBody MsgListRequest msgListRequest, HttpServletRequest request) {
        return msgService.selShop(msgListRequest, request);
    }
}
